from dataclasses import dataclass
from typing import List, Set
from .meta_processor import MetaInfoContainer

@dataclass
class VueMetaInfo:
    """Vue特定的元数据处理"""
    container: MetaInfoContainer

    @property
    def form_columns(self) -> List[dict]:
        """获取表单字段"""
        return [col for col in self.container.columns_meta if col['editable']]

    @property
    def search_columns(self) -> List[dict]:
        """获取搜索字段"""
        return [col for col in self.container.columns_meta if col['searchable']]

    @property
    def list_columns(self) -> List[dict]:
        """获取列表字段"""
        return [col for col in self.container.columns_meta if col['listable']]

    @property
    def primary_key(self) -> dict:
        """获取主键信息（单主键）"""
        primary_keys = self.container.primary_keys
        if len(primary_keys) == 1:
            return primary_keys[0]
        return {}

@dataclass
class SpringBootMetaInfo:
    """SpringBoot特定的元数据处理"""
    container: MetaInfoContainer
    package_name: str

    @property
    def entity_columns(self) -> List[dict]:
        """获取实体字段"""
        return self.container.columns_meta

    def get_imports(self) -> List[str]:
        """获取需要导入的包"""
        imports: Set[str] = set()
        for col in self.container.columns_meta:
            type_name = col['language_type']
            if type_name in ['LocalDateTime', 'LocalDate', 'LocalTime']:
                imports.add(f'java.time.{type_name}')
            elif type_name == 'BigDecimal':
                imports.add('java.math.BigDecimal')
        return sorted(list(imports))

    @property
    def primary_key(self) -> dict:
        """获取主键信息（单主键）"""
        primary_keys = self.container.primary_keys
        if len(primary_keys) == 1:
            return primary_keys[0]
        return {}